package com.znsd.study.controllor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.znsd.entitys.MsgInfo;
import com.znsd.study.service.MsgService;

@Controller
public class MsgControll {
	@Autowired
	private MsgService msgService;
	
	@ResponseBody
	@RequestMapping(value = "msg" ,method = RequestMethod.POST)
	public Map<String, Object> msg(String recp_id,HttpServletRequest request){
		HttpSession session = request.getSession();
		System.out.println(recp_id);
		Map<String, Object> map=new HashMap<String, Object>();
		if(recp_id==null) {
			recp_id="0";
		}
		List<MsgInfo> list = msgService.queryMsg(Integer.parseInt(recp_id));
		//session.setAttribute("msg", list);
		map.put("list", list);
		map.put("count", list.size());
		return map;
	}
	
	@ResponseBody
	@RequestMapping(value = "yd" ,method = RequestMethod.POST)
	public String ydmsg(@RequestBody List<MsgInfo> list,HttpServletRequest request) {
		//System.out.println("__________________________________________________________");
		HttpSession session = request.getSession();
		int con=0;
		for (MsgInfo m : list) {
			con+=msgService.delMsg(m.getM_id());
		}
		System.out.println(list);
		return con+"";
	}
	
	
}
